/*************************************************************************
	> File Name: P1049.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2024-12-19 15:44:29
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 30
#define MAX_V 20000

int dp[MAX_V + 5];

int main() {
    int V, n;
    cin >> V >> n;
    for (int i = 1, w; i <= n; i++) {
        cin >> w;
        for (int j = V; j >= w; j--) {
            dp[j] = max(dp[j], dp[j - w] + w);
        }
    }
    cout << V - dp[V] << endl;
    return 0;
}
